<template>
  <div class="app">
    <van-nav-bar
      title="注册"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />

    <p><van-icon name="user-circle-o" class="icc" /></p>

    <van-form class="form">
      <van-field
        v-model="nickname"
        name="nickname"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
        style="
          width: 300px;
          height: 40px;
          border-radius: 40px;
          margin-bottom: 10px;
        "
      />
      <van-field
        v-model="phone"
        type="text"
        name="phone"
        label="手机号码"
        placeholder="请输入手机号码"
        :rules="[{ required: true, message: '请填写手机号码' }]"
        style="
          width: 300px;
          height: 40px;
          border-radius: 40px;
          margin-bottom: 10px;
        "
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
        style="
          width: 300px;
          height: 40px;
          border-radius: 40px;
          margin-bottom: 10px;
        "
      />
      <div class="yanzheng">
        <van-field
          v-model="captcha"
          type="text"
          name="captcha"
          label="验证码"
          :rules="[{ required: true, message: '请填写验证码' }]"
          style="
            width: 180px;
            height: 40px;
            border-radius: 40px;
            margin-bottom: 10px;
          "
        />
        <van-button style="width: 110px" @click="yanzhengfs"
          >发送验证码</van-button
        >
      </div>

      <div class="zhuce" style="margin: 16px">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          style="width: 100px"
          :to="{ name: 'Login' }"
        >
          登录</van-button
        >
        <van-button
          round
          block
          type="info"
          native-type="submit"
          style="width: 100px"
          @click="tologin()"
          >注册</van-button
        >
      </div>
      <!-- @click="clickHandle" -->
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
import { SentRegAPI } from "../services/Reg";
export default {
  data() {
    return {
      nickname: "",
      password: "",
      phone: "",
      captcha: "",
    };
  },
  created() {},
  methods: {
    onClickLeft() {
      this.$router.push({
        name: "Jump",
      });
    },
    yanzhengfs() {
      SentRegAPI(this.phone);
    },
    async tologin() {
      if (this.nickname && this.password && this.phone && this.captcha) {
        Toast.success({
          message: "注册成功",
        });
        this.$router.push({
          name: "Login",
        });
      } else {
        Toast.fail({
          message: "注册失败，请检查信息是否完整",
        });
      }
    },
  },
};
</script>

<style scoped>
body,
html,
.app {
  width: 100vw;
  background-color: rgb(61, 206, 238);
}
p {
  text-align: center;
  margin: 40px;
}
.icc {
  color: white;
  font-size: 120px;
  margin: 0 auto;
}
.form {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.yanzheng {
  display: flex;
  flex-direction: row;
}
.zhuce {
  display: flex;
  justify-content: space-evenly;
}
</style>
